Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rename enum types to singular #1064

Merged
merged 1 commit into from
Apr 2, 2021

Conversation

wayneseymour
Copy link
Member

@wayneseymour wayneseymour commented Mar 8, 2021

Simple search and replace...low hanging fruit.
Also, not sure if the markdown files should be included in this refactor?

fix #767

Summary

I was searching for an easy pr to start understanding this repo.

I think there are still more enums to fixup, such as:

export const SpecTypes = Object.freeze({

@wayneseymour wayneseymour self-assigned this Mar 8, 2021
@wayneseymour wayneseymour requested a review from monfera March 8, 2021 22:53
@codecov-io
Copy link

codecov-io commented Mar 8, 2021

Codecov Report

Merging #1064 (c07d621) into master (c89b767) will increase coverage by 0.42%.
The diff coverage is 82.75%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1064      +/-   ##
==========================================
+ Coverage   71.72%   72.14%   +0.42%     
==========================================
  Files         381      397      +16     
  Lines       11918    12232     +314     
  Branches     2600     2648      +48     
==========================================
+ Hits         8548     8825     +277     
- Misses       3339     3368      +29     
- Partials       31       39       +8     
Flag Coverage Δ
unittests 71.72% <82.84%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/chart_types/xy_chart/utils/series.ts 96.88% <ø> (ø)
src/specs/index.ts 100.00% <ø> (ø)
src/chart_types/goal_chart/state/chart_state.tsx 57.62% <50.00%> (ø)
...l_chart/state/selectors/on_element_click_caller.ts 56.25% <50.00%> (ø)
...oal_chart/state/selectors/on_element_out_caller.ts 53.33% <50.00%> (ø)
...al_chart/state/selectors/on_element_over_caller.ts 53.33% <50.00%> (ø)
...hart_types/heatmap/layout/types/viewmodel_types.ts 54.54% <50.00%> (ø)
src/chart_types/heatmap/state/chart_state.tsx 63.76% <50.00%> (ø)
...pes/heatmap/state/selectors/on_brush_end_caller.ts 35.71% <50.00%> (ø)
...heatmap/state/selectors/on_element_click_caller.ts 31.03% <50.00%> (ø)
... and 75 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c89b767...c07d621. Read the comment docs.

@wayneseymour wayneseymour requested a review from markov00 March 9, 2021 20:55
@monfera
Copy link
Contributor

monfera commented Mar 10, 2021

Thanks @wayneseymour for your PR!

  • The api/charts.api.md file can be regenerated with yarn build:ts && yarn api:extract and the output file (that gets output a different location) can becp tmp/charts.api.md api/charts.api.md-ed in place of api/charts.api.md and checked eg. via diffing if the changes are as you expect
  • The source change looks good, wondering @markov00 what our policy is for approving/merging PRs that break the API without a linked requirement by the dependency, Kibana—I guess it's best to batch such changes to minimize the # of BREAKING. But batching means, longer wait till it hits master, with inevitable merge conflicts, as a maintenance PR impacts many lines. Future additions of ChartTypes also won't be covered (TS checks should catch this). Ie. there's more work than usual on the part of the PR maker and whoever works on future merges
  • It's good to run tests locally too, including, in such cases when many files are changed, the image tests, glad to help setting it up; besides firing up storybook and testing a variety of charts manually
  • Tre' a note for merge time, elastic-charts has commit message content conventions for breaking changes, see here

Tre' one note is that sometimes we're assisting Kibana users in such API changes, eg. via small PRs there by the chart PR maker 😉 That's also a reason for, I think, merging a bunch of API breaking changes in one fell swoop, Marco what do you think, with 7.12 around the corner?

@markov00
Copy link
Member

Thank you Tre'!
This should definitely include the BREAKING CHANGE footer
We can merge this and update 7.13 branch, it will not be merged on 7.12 as we can't introduce breaking changes after FF

I think it's fine to include multiple changes here, some enums are not currently used much outside the library

@nickofthyme
Copy link
Collaborator

Thanks @wayneseymour this issue is very near and dear to my ❤️

@monfera I think this is just a nice to have that will eventually get into 7.13 so I don't think we need to be too critical of batching other PRs nor waiting to get others merged before this as we could just backport any critical changes to 7.12 in the few remaining days. Also we end up having to merge the PRs so one of us should be sure to note the BREAKING CHANGE.

@wayneseymour
Copy link
Member Author

Thanks @wayneseymour for your PR!

  • The api/charts.api.md file can be regenerated with yarn build:ts && yarn api:extract and the output file (that gets output a different location) can becp tmp/charts.api.md api/charts.api.md-ed in place of api/charts.api.md and checked eg. via diffing if the changes are as you expect
  • The source change looks good, wondering @markov00 what our policy is for approving/merging PRs that break the API without a linked requirement by the dependency, Kibana—I guess it's best to batch such changes to minimize the # of BREAKING. But batching means, longer wait till it hits master, with inevitable merge conflicts, as a maintenance PR impacts many lines. Future additions of ChartTypes also won't be covered (TS checks should catch this). Ie. there's more work than usual on the part of the PR maker and whoever works on future merges
  • It's good to run tests locally too, including, in such cases when many files are changed, the image tests, glad to help setting it up; besides firing up storybook and testing a variety of charts manually
  • Tre' a note for merge time, elastic-charts has commit message content conventions for breaking changes, see here

Tre' one note is that sometimes we're assisting Kibana users in such API changes, eg. via small PRs there by the chart PR maker 😉 That's also a reason for, I think, merging a bunch of API breaking changes in one fell swoop, Marco what do you think, with 7.12 around the corner?

Awesome, I'll get on this next week! "Shut it down day" tomorrow in the US :)

@wayneseymour
Copy link
Member Author

Thank you Tre'!
This should definitely include the BREAKING CHANGE footer
We can merge this and update 7.13 branch, it will not be merged on 7.12 as we can't introduce breaking changes after FF

I think it's fine to include multiple changes here, some enums are not currently used much outside the library

Perfect, I'll fixup asap! Thanks for reviewing!

@wayneseymour wayneseymour force-pushed the rename-enum-types-to-singular branch 2 times, most recently from 93b025c to 52b37c5 Compare March 25, 2021 22:29
@wayneseymour
Copy link
Member Author

@monfera @nickofthyme Gents, I'm not sure how to proceed here.
The issue is with symbol shadowing. In this case, the object and the type would have the same name if I refactored away the plurality.
Ideas?

Screen Shot 2021-03-26 at 1 19 55 PM

@monfera
Copy link
Contributor

monfera commented Mar 26, 2021

@wayneseymour that's fine, please see eg. LegendStrategy or other similar symbols that get dual-bound (one value, one type) as part of our current approach of working around (or rather, avoid) TypeScript enums

export type LegendStrategy = Values<typeof LegendStrategy>;

BREAKING CHANGE: The "enums" are no longer plural in signature.

fix #767

Signed-off-by: Tre' Seymour <[email protected]>
@wayneseymour wayneseymour force-pushed the rename-enum-types-to-singular branch from aa444a8 to c07d621 Compare April 1, 2021 18:31
@wayneseymour wayneseymour marked this pull request as ready for review April 1, 2021 21:31
@wayneseymour wayneseymour requested a review from nickofthyme April 1, 2021 21:31
@wayneseymour
Copy link
Member Author

Locally, I've run these build scripts and they passed:

  • yarn build:ts && yarn api:extract
  • yarn lint:fix
  • yarn test

Copy link
Member

@markov00 markov00 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, scanned all the changes online and looks great!
Thanks for taking the time for that.
Just remember to add a breaking change line in the merge commit like the following:

your PR description

BREAKING CHANGE: `AnnotationDomainTypes`, `AnnotationType` and all the others (please list them) are renamed to ....

@wayneseymour
Copy link
Member Author

LGTM, scanned all the changes online and looks great!
Thanks for taking the time for that.
Just remember to add a breaking change line in the merge commit like the following:

your PR description

BREAKING CHANGE: `AnnotationDomainTypes`, `AnnotationType` and all the others (please list them) are renamed to ....

Indeed I will! Thanks @markov00

@wayneseymour wayneseymour merged commit 396b3d1 into master Apr 2, 2021
@wayneseymour wayneseymour deleted the rename-enum-types-to-singular branch April 2, 2021 16:43
nickofthyme pushed a commit that referenced this pull request Apr 2, 2021
# [28.0.0](v27.0.0...v28.0.0) (2021-04-02)

### Bug Fixes

* **annotations:** provide fallback for line annotation markers ([#1091](#1091)) ([0bd61f1](0bd61f1))
* **legend:** action sizing ui and focus states ([#1102](#1102)) ([3a76a2c](3a76a2c))
* **legend:** stop legend color picker dot twitching ([#1101](#1101)) ([c89b767](c89b767))

### Code Refactoring

* rename enum types to singular ([#1064](#1064)) ([396b3d1](396b3d1)), closes [#767](#767)

### BREAKING CHANGES

* `AnnotationDomainTypes`, `AnnotationTypes`, `SeriesTypes`, `ChartTypes`, and `SpecTypes` are renamed to `AnnotationDomainType`, `AnnotationType`, `SeriesType`, `ChartType`, and `SpecType`
@nickofthyme
Copy link
Collaborator

🎉 This PR is included in version 28.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@nickofthyme nickofthyme added the released Issue released publicly label Apr 2, 2021
@nickofthyme
Copy link
Collaborator

Gents, I'm not sure how to proceed here.
The issue is with symbol shadowing. In this case, the object and the type would have the same name if I refactored away the plurality.
Ideas?

Hey @wayneseymour I was sick last week so I didn't see this till now and wanted to clear this up in case you ran into this in the future. I'm thinking this might be an issue with the linter because in typescript when exporting a type or value you create a separate entity for each, so the naming will not clash when doing something like...

export const SeriesType = Object.freeze({
  Area: 'area' as const,
  Bar: 'bar' as const,
  Line: 'line' as const,
  Bubble: 'bubble' as const,
});
export type SeriesType = $Values<typeof SeriesType>;

Typescript calls this Declaration Merging whereby the type and value (and namespaces) are merged into one as SeriesType wherever it is imported. In this case, we call this a const enum as it is not a typescript enum, see elastic/kibana#62957 (comment) for a deeper explanation of why.

AMoo-Miki pushed a commit to AMoo-Miki/OpenSearch-Dashboards that referenced this pull request Feb 10, 2022
# [28.0.0](elastic/elastic-charts@v27.0.0...v28.0.0) (2021-04-02)

### Bug Fixes

* **annotations:** provide fallback for line annotation markers ([opensearch-project#1091](elastic/elastic-charts#1091)) ([d907c81](elastic/elastic-charts@d907c81))
* **legend:** action sizing ui and focus states ([opensearch-project#1102](elastic/elastic-charts#1102)) ([a58cc0a](elastic/elastic-charts@a58cc0a))
* **legend:** stop legend color picker dot twitching ([opensearch-project#1101](elastic/elastic-charts#1101)) ([f63bb3b](elastic/elastic-charts@f63bb3b))

### Code Refactoring

* rename enum types to singular ([opensearch-project#1064](elastic/elastic-charts#1064)) ([6e900e2](elastic/elastic-charts@6e900e2)), closes [opensearch-project#767](elastic/elastic-charts#767)

### BREAKING CHANGES

* `AnnotationDomainTypes`, `AnnotationTypes`, `SeriesTypes`, `ChartTypes`, and `SpecTypes` are renamed to `AnnotationDomainType`, `AnnotationType`, `SeriesType`, `ChartType`, and `SpecType`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change released Issue released publicly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rename enum types to singular
5 participants